package use_case.processRental;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import use_case.processRental.RentUI.PaymentListener;


public class CouponUI {

	private JFrame cframe;
	private JTextField textField;
	private RentUI rentUI;

	
	/**
	 * Create the application.
	 */
	public CouponUI(RentUI rentUI) {
		this.rentUI = rentUI;
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		cframe = new JFrame("Discount");
		cframe.setBounds(100, 100, 450, 300);
		cframe.getContentPane().setBackground(new Color(180, 0, 0));
		cframe.getContentPane().setLayout(null);
		cframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		
		JLabel lblEntryCode = new JLabel("Code:");
		lblEntryCode.setForeground(Color.WHITE);
		lblEntryCode.setFont(new Font("Tahoma", Font.BOLD, 18));
		lblEntryCode.setBounds(39, 13, 61, 31);
		cframe.getContentPane().add(lblEntryCode, BorderLayout.CENTER);
		
		textField = new JTextField();
		textField.setBounds(112, 15, 71, 31);
		cframe.getContentPane().add(textField);
		textField.setColumns(10);
		
		
		JButton btnEnter = new JButton("Enter");
		btnEnter.setBounds(75, 57, 85, 30);
		cframe.getContentPane().add(btnEnter);
		btnEnter.addActionListener(new EnterBtnListener());
		
		
		
		cframe.setSize(250,150);
		cframe.setVisible(true);
	}
	
	class EnterBtnListener   implements ActionListener{
		
		public void actionPerformed(ActionEvent event){
			
			if (textField.getText().equals("Coupon")){
				rentUI.setDiscount(textField.getText());
			}
			else if (textField.getText().equals("Percent")){
				rentUI.setDiscount(textField.getText());
			}
			
			cframe.setVisible(false);
			cframe.dispose();
			
		}
	}//end inner class
	
	
}
